package org.yzhzc.job.mapper.user;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.yzhzc.job.domain.user.dto.UserScoreDTO;
import org.yzhzc.job.domain.user.entity.UserSubmit;


import java.util.List;
import java.util.Set;

public interface UserSubmitMapper extends BaseMapper<UserSubmit> {

    /**
     * 查询用户成绩列表
     *
     * @param examIdSet 包含多个 examId 的集合
     * @return 用户成绩列表
     */
    @Select("<script>" +
            "SELECT " +
            "    exam_id, " +
            "    user_id, " +
            "    sum(score) as score " +
            "FROM " +
            "    tb_user_submit " +
            "WHERE " +
            "    exam_id in " +
            "    <foreach collection='examIdSet' item='examId' open='(' close=')' separator=','> " +
            "        #{examId} " +
            "    </foreach> " +
            "GROUP BY " +
            "    exam_id, user_id " +
            "ORDER BY " +
            "    score DESC" +
            "</script>")
    List<UserScoreDTO> selectUserScoreList(@Param("examIdSet") Set<Long> examIdSet);

    /**
     * 查询热门问题列表
     *
     * @return 热门问题的 ID 列表
     */
    @Select("SELECT " +
            "    question_id, " +
            "    count(question_id) hot_count " +
            "FROM " +
            "    tb_user_submit " +
            "WHERE " +
            "    exam_id is null " +
            "GROUP BY " +
            "    question_id " +
            "ORDER BY " +
            "    hot_count DESC")
    List<Long> selectHostQuestionList();
}
